#pragma once
#include "GRiComponent.h"
#include "GRiCmpTransform.h"
#include "GRiCmpGeometry.h"
#include "GRiCmpMaterial.h"
#include "GRiCmpLight.h"
#include "GRiBounds3Box.h"
class GRiObj
{
public:
	GRiObj() {
		GUPtr<GRiComponent> cmp(new GRiCmpTransform(this));
		AddComponent(std::move(cmp));
	};

	void AddComponent(GUPtr<GRiComponent> comp);

	void AddComponent(GUSPtr<GRiComponent> comp);

	template<typename T>
	bool HasComponent();

	template<typename T>
	T* GetComponent();

	GRiBounds3Box GetBoundingBox();
protected:

public:


	std::string UniqueName;
	std::unordered_map<std::type_index,GUPtr<GRiComponent>> mComponents;
};

template<typename T>
bool GRiObj::HasComponent()
{
	auto temp = mComponents.find(std::type_index(typeid(T)));

	return temp != mComponents.end();
}

template<typename T>
inline T* GRiObj::GetComponent()
{

	auto temp = mComponents[std::type_index(typeid(T))].get();

	T* ptr = dynamic_cast<T*>(temp);

	return ptr;
	// TODO: 在此处插入 return 语句
}
